define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hkstore/index',
                    add_url: 'hkstore/add',
                    edit_url: 'hkstore/edit',
                    del_url: 'hkstore/del',
                    multi_url: 'hkstore/multi',
                    table: 'hk_store',
                }
            });

            //按钮数组
            var button_arr = [
                {
                    name: 'read',
                    text: __('Edit'),
                    title: __('Edit'),
                    icon: 'fa fa-edit',
                    classname: 'btn btn-xs btn-success btn-dialog', url: 'Hkstore/edit'},
                {
                    name: 'del',
                    text: __('Del'),
                    title: __('Del'),
                    icon: 'fa fa-trash',
                    classname: 'btn btn-xs btn-ajax btn-danger btn-delone',
                    url: 'Hkstore/del',
                    confirm: '确定要执行该操作吗?'},
                {
                    name: 'qrcode',
                    text:__('二维码生成'),
                    title:__('二维码生成'),
                    icon: 'fa fa-edit',
                    classname: 'btn btn-xs btn-info btn-dialog',
                    url:'Hkstore/qrCode'
                }
            ];

            if(use_type != 0){ //广告商角色
                button_arr.splice(1,1);
            }

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 's_name', title: __('S_name')},
                        {field: 's_image', title: __('S_image'), formatter: Table.api.formatter.image},
                        //{field: 's_images', title: __('S_images'), formatter: Table.api.formatter.images},
                        {field: 's_score', title: __('S_score')},
                        {field: 's_address', title: __('S_address')},
                        //{field: 'pos_latitude', title: __('Pos_latitude')},
                        //{field: 'pos_longitude', title: __('Pos_longitude')},
                        {field: 'service_phone', title: __('Service_phone')},
                        {field: 'contact_name', title: __('Contact_name')},
                        //{field: 'card_obverse_image', title: __('Card_obverse_image'), formatter: Table.api.formatter.image},
                        //{field: 'card_recite_image', title: __('Card_recite_image'), formatter: Table.api.formatter.image},
                        //{field: 'licence_image', title: __('Licence_image'), formatter: Table.api.formatter.image},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
                        {field: 'id', title: __('Operate'), table: table, buttons: button_arr, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,operate:false}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
            //在加载完成后
            $(function(){
                //被选中的值
                var check = $("input[name='row[check_data]']:checked").val();
                var reason = $('#reason-box');
                if(check == 2){ //为不通过时,显示输入原因
                    reason.removeClass('hidden');
                }
                var check_data = $("input[name='row[check_data]']");
                check_data.change(function(){
                    if($(this).val() == 2){
                        reason.removeClass('hidden');
                    }else{
                        reason.addClass('hidden');
                    }
                });
            });
        },
        qrcode: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});